<template>
  <el-form :model="SearchInfor" :inline="true" class="demo-form-inline">
    <el-form-item label="项目名称">
      <el-input
        @change="TsInforSearch"
        clearable
        v-model="SearchInfor.projectName"
        placeholder="项目名称"
      />
    </el-form-item>
    <el-form-item label="开始时间">
      <el-date-picker
        @change="TsInforSearch"
        clearable
        v-model="SearchInfor.beginDate"
        type="datetime"
        placeholder="开始时间"
        format="YYYY/MM/DD HH:mm:ss"
      />
    </el-form-item>
    <el-form-item label="结束时间">
      <el-date-picker
        @change="TsInforSearch"
        clearable
        v-model="SearchInfor.endDate"
        type="datetime"
        placeholder="结束时间"
        format="YYYY/MM/DD HH:mm:ss"
      />
    </el-form-item>
    <el-form-item label="暂存类型">
      <el-select
        @change="TsInforSearch"
        v-model="SearchInfor.transientType"
        placeholder="暂存类型"
      >
        <el-option label="所有" :value="null">所有</el-option>
        <el-option label="立项暂存" :value="0">立项暂存</el-option>
        <el-option label="变更暂存" :value="1">变更暂存</el-option>
      </el-select>
    </el-form-item>
  </el-form>
  <el-table :data="TSInfor" style="width: 100%">
    <el-table-column prop="tsId" label="暂存编码"> </el-table-column>
    <el-table-column prop="userId" label="用户名"> </el-table-column>
    <el-table-column prop="projectName" label="项目名称"> </el-table-column>
    <el-table-column prop="projectCreateTime" label="项目创建时间">
    </el-table-column>
    <el-table-column prop="createTime" label="暂存时间"> </el-table-column>
    <el-table-column label="操作">
      <template #default="slot">
        <el-button type="success" @click="TSInforDesc(slot.row)"
          >详情</el-button
        >
        <el-button type="danger" @click="TsInforDelete(slot.row)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    v-model:current-page="SearchInfor.index"
    v-model:page-size="SearchInfor.size"
    :page-sizes="[5, 10, 15, 20]"
    :background="true"
    layout="total, sizes, prev, pager, next, jumper"
    :total="Total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>

<script>
export default {
  data() {
    return {
      SearchInfor: {
        userName: JSON.parse(localStorage.getItem("user")).userName,
        projectName: "",
        beginDate: null,
        endDate: null,
        index: 1,
        size: 5,
        transientType: null,
      },
      TSInfor: [],
      Total: 0,
    };
  },
  created() {
    this.TsInforSearch();
  },
  methods: {
    TsInforSearch() {
      this.http
        .post("api/tb_project_tsinfo/TsInforSearch", this.SearchInfor)
        .then((res) => {
          this.TSInfor = res.data.list;
          this.Total = res.data.total;
        });
    },
    TsInforDelete(row) {
      this.$confirm("确认删除该暂存吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.http
            .post("api/tb_project_tsinfo/DelTs?Id=" + row.tsId)
            .then((res) => {
              if (res.status) {
                this.$message({
                  type: "success",
                  message: "删除成功",
                });
                this.TsInforSearch();
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    TSInforDesc(row) {
      console.log(row.tsId);
      if (row.transientType == 0) {
        this.$router.push("/AddApproval?id=" + row.tsId);
      } else {
        this.$router.push("/UptApproval?id=" + row.tsId);
      }
    },
    handleSizeChange(val) {
      this.SearchInfor.size = val;
      this.TsInforSearch();
    },
    handleCurrentChange(val) {
      this.SearchInfor.index = val;
      this.TsInforSearch();
    },
  },
};
</script>